/* @(#)GSMarketInfoManageQueryAction.java
 * 
 *  Project:GS
 *  
 *  Modify  Information:
 *  ===============================================
 *   Author          Date            Description
 *  -------------- ---------------  ---------------
 *  Jenny  Li      2006-5-26          新增
 * Copyright Notice:
 * =============================================================================
 *    Copyright (c) 2001-2006 Beijing HiTRUST Technology Co., Ltd. 1808 Room, 
 *        Science & Technology Building, No. 9 South Street, Zhong Guan Cun, 
 *        Haidian District, Beijing ,100081, China All rights reserved.
 *
 *    This software is the confidential and proprietary information of
 *        Beijing HiTRUST Technology Co., Ltd. ("Confidential Information").
 *        You shall not disclose such Confidential Information and shall use it
 *        only in accordance with the terms of the license agreement you entered
 *        into with HiTRUST.
 *
 * Warning:
 * =============================================================================
 *
 */
package com.hitrust.gs.action;

import java.util.ArrayList;

import com.hitrust.gs.business.GSMarketInfoProcessor;
import com.hitrust.gs.dao.GSMarketInfoDAO;
import com.hitrust.gs.dao.GSOrderDetailDAO;
import com.hitrust.gs.form.GSMarketInfoQueryForm;
import com.hitrust.gs.lib.GSBaseConstants;
import com.hitrust.gs.service.GSBaseAction;
import com.hitrust.gs.service.GSBaseForm;
import com.hitrust.gs.service.GSBaseManager;
import com.hitrust.gs.util.date.DateUtil;
import com.hitrust.gs.util.page.ResultProcess;
import com.hitrust.gs.vo.GSMarketInfoQryVO;
import com.hitrust.gs.vo.GSOrderVO;

/**
 * @author JennyLi
 *
 */
public class GSMarketInfoManageQueryAction extends GSBaseAction {

    /* (non-Javadoc)
     * @see com.hitrust.gs.service.GSBaseAction#execute(com.hitrust.gs.service.GSBaseForm)
     */
    public String execute(GSBaseForm aForm) throws Exception {

        GSMarketInfoQueryForm tForm = (GSMarketInfoQueryForm)aForm;
        
        GSMarketInfoQryVO tVO = new GSMarketInfoQryVO();
        tVO.title = tForm.getTitle();
        tVO.content = tForm.getContent();
        tVO.providerId = tForm.getProvider();
        
        String[] tDate = new String[2];
        tDate[0] = tForm.getPublishDateStr();
        tDate[1] = tForm.getPublishDateEnd();
        tDate = DateUtil.formateDate(tDate);
        tVO.publishDateStr = tDate[0]; 
        tVO.publishDateEnd = tDate[1];
        //取得分页参数        
        String[] tStr = this.getPageParams(tForm,tVO);
        
        GSMarketInfoProcessor tMarketInfoProc = new GSMarketInfoProcessor();
        ArrayList tList = tMarketInfoProc.getMarketInfoByOpt(tVO,Integer.parseInt(tStr[0]),Integer.parseInt(tStr[1]));
        ResultProcess tRsProc = new ResultProcess();
        tRsProc.setResult(tList);
        tForm.getRequest().setAttribute("marketinfo",tRsProc);
        //存储分页参数
        tForm.getRequest().setAttribute("pageSize",tStr[1]);
        tForm.getRequest().setAttribute("totalRecords",tStr[2]);
        
        return GSBaseConstants.FORWARD_SUCCESS;
    }
    private String[] getPageParams(GSBaseForm aForm,GSMarketInfoQryVO aVO) throws Exception{
        String tStr[] = new String[3];
        int totalRecords;
        int pageNo;
        int pageSize;
        String tPage = GSBaseConstants.tPage;
        GSMarketInfoDAO tMarketInfoDAO = new GSMarketInfoDAO();
        //根据页面传入的查询参数查询订单信息
        if(aForm.getChoice() == null || aForm.getChoice().equals("")){
            totalRecords = tMarketInfoDAO.queryMarketInfoCountByOpt(aVO);
            // 取得系统默认的页大小
            pageSize = Integer.parseInt(tPage);
            // PageNo=1
            pageNo = 1;
            int n = (totalRecords % pageSize == 0 )? totalRecords / pageSize:totalRecords / pageSize + 1;
            if (pageNo>n) {
                pageNo=n;
            }
            tStr[0] = "" + pageNo;
            tStr[1] = "" + pageSize;
            tStr[2] = "" + totalRecords;
        }else{
            tStr = GSBaseManager.getPageNoAndPageSize(aForm);
        }
        return tStr;
    }

}
